#!/usr/bin/env python
# encoding: utf-8

import requests, json, urllib, urllib2

def get_access_token(url_prefix, auth_data):
	#url_prefix = 'http://api-qa.jiankongbao.com'
	#auth_data = {'grant_type': 'password', 'username': 'rachel_wang02@163.com', 'password':'e10adc3949ba59abbe56e057f20f883e', 'client_id':'123', 'client_secret':'668e7c8391ff7ec8b98bb07b757583e08c8b1c3e'}
	url_postfix = '/v2/oauth/token.json'
	url = url_prefix + url_postfix
	response = requests.post(url, data=auth_data)
	return json.loads(response.text)['access_token'], auth_data
	#print(json.loads(response.text)['access_token']), (auth_data)
	#print type(json.loads(response.text))

def main():
	auth_data = {'grant_type': 'password', 'username': 'rachel_wang02@163.com', 'password':'e10adc3949ba59abbe56e057f20f883e', 'client_id':'123', 'client_secret':'668e7c8391ff7ec8b98bb07b757583e08c8b1c3e'}
	m = get_access_token('http://api-qa.jiankongbao.com', auth_data)
	print m
	print m[0]
	print type(m[1])

if __name__ == '__main__':
	main()	
